package com.xjk.consumer9100.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * @author: XJK
 */
@Controller
@RequestMapping("/a2")
public class MyController {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${server.port}")
    private String port;

    @Value("${service-url.nacos-server-providers}")
    private String providerUrl;

    @RequestMapping(value = "/get",method = RequestMethod.GET)
    @ResponseBody
    public String get(){
        return "hello,nacos. myPort is"+port;
    }


    @ResponseBody
    @RequestMapping(value = "/gU",method = RequestMethod.GET)
    public String getProviderUrl(){
        // 通过Ribbon进行负载均衡,基于RestFul的Url进行远程调用, url手动拼接,以访问Provider中的Controller
        return restTemplate.getForObject(providerUrl+"/a1/get",String.class);
    }


}
